package com.teafriend.controller;

import com.teafriend.entity.Goods;
import com.teafriend.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单控制器
 * @author 欧楚杨
 */
@RestController
@RequestMapping("/chuyangc/goods/")
@Api(tags = "订单相关的请求")
public class GoodsController {
    @Autowired
    GoodsService goodsService;

    @GetMapping("/listgoods")
    @ApiOperation("查询所有订单信息")
    @ApiImplicitParam()
    public List<Goods> listGoods(){
        return goodsService.list();
    }

    @DeleteMapping("/delgoods/{id}")
    @ApiOperation("根据订单id删除数据")
    @ApiImplicitParam(name = "订单id",value = "id",required = true)
    public boolean delGoods(@PathVariable("id") Integer id){
        return goodsService.removeById(id);
    }

    @PostMapping("/addgoods")
    @ApiOperation("添加订单")
    @ApiImplicitParam(name = "订单实体类对象",value = "goods",required = true)
    public boolean addGoods(@RequestBody Goods goods){
        return goodsService.save(goods);
    }

    @GetMapping("/searchgoods/{id}")
    @ApiOperation("根据id查找订单")
    @ApiImplicitParam(name = "订单id",value = "id",required = true)
    public Goods searchGoods(@PathVariable Integer id){
        return goodsService.getById(id);
    }

    @PostMapping("/updategoods")
    @ApiOperation("根据订单id修改信息")
    @ApiImplicitParam(name = "订单实体类对象",value = "goods",required = true)
    public boolean updateGoods(@RequestBody Goods goods){
        return goodsService.updateById(goods);
    }
}
